package com.base.andlanggl.data

import android.opengl.GLES20.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.FloatBuffer

/**
 * 封装存储顶点矩阵的FloatBuffer
 */
class VertexArray(vertexData:FloatArray) {
    companion object{
        const val BYTES_PER_FLOAT:Int=4
    }
    var floatBuffer:FloatBuffer = ByteBuffer.allocateDirect(vertexData.size*BYTES_PER_FLOAT)
        .order(ByteOrder.nativeOrder()).asFloatBuffer().put(vertexData)

    fun setVertexAttribPointer(dataOffset:Int,attributeLocation:Int,componentCount:Int,stride:Int){
        floatBuffer.position(dataOffset)
        glVertexAttribPointer(attributeLocation,componentCount, GL_FLOAT,false,stride,floatBuffer)
        glEnableVertexAttribArray(attributeLocation)
        floatBuffer.position(0)
    }

}